/**
 * 检查输赢
 * @param circles
 * @param x
 * @param y
 * @param isBlack
 * @returns {number|number}
 */
const check = (circles, x, y, isBlack) => {
    const chess = isBlack ? 1 : 2
    let count = 0;
    //纵向
    for (let i = x - 4; i < x + 5; i++) {
        if (i < 0 || i > 18) {
            continue
        } else {
            if (circles[i][y] === chess) {
                count++;
                if (count >= 5) {
                    return chess
                }
            } else {
                count = 0;
            }
        }
    }
    count = 0;
    //横向
    for (let i = y - 4; i < y + 5; i++) {
        if (i < 0 || i > 18) {
            continue
        } else {
            if (circles[x][i] === chess) {
                count++;
                if (count >= 5) {
                    return chess
                }
            } else {
                count = 0;
            }
        }
    }
    count = 0;
    //左上到右下
    for (let i = -4; i < 5; i++) {
        if (x + i < 0 || x + i > 18 || y + i < 0 || y + i > 18) {
            continue
        } else {
            if (circles[x + i][y + i] === chess) {
                count++;
                if (count >= 5) {
                    return chess
                }
            } else {
                count = 0;
            }
        }
    }
    count = 0;
    //右上到左下
    for (let i = -4; i < 5; i++) {
        if (!(x + i < 0 || x + i > 18 || y - i < 0 || y - i > 18)) {
            continue
        } else {
            if (circles[x + i][y - i] === chess) {
                count++;
                if (count >= 5) {
                    return chess
                }
            } else {
                count = 0;
            }
        }
    }
    return 0
}

export {
    check
}